package com.service.socket.ws.task;

import com.service.socket.common.entity.SendMessageVo;
import com.service.socket.common.enums.MsgSendType;
import com.service.socket.ws.TradingSpotWS;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class WebsocketPingTask {

    @Autowired
    TradingSpotWS spotWS;

    @Scheduled(cron = "0/55 * * * * ?")
    public void doSchedule() {
        log.info("websocket ping-定时任务");
        SendMessageVo sendMessageVo = SendMessageVo.builder()
                .type(MsgSendType.ping.getMsg())
                .data(new Date().getTime())
                .build();
        spotWS.broadcastPingMsg(sendMessageVo);
    }

}
